{extend name="common/base" /}
{block name="body"}
<div style="background: #6C70DE;">
    <div class="sjrz-mains">
        <img src="__CDN__/html/img/tu-1.png" class="img1">
        <div class="sjrz-wk">
            <ul class="sjrz-input">
                <li>
                    <div class="in-le">手机号</div>
                    <input type="text" class="in-ce in-ce2 js-phone" placeholder="请填写手机号">
                    <div class="in-hq js-yzm" is_allow_click='1'>获取验证码</div>
                </li>        
                <li>
                    <div class="in-le">验证码</div>
                    <input type="text" class="in-ce js-code" placeholder="请填写短信验证码">
                </li>
                <li>
                    <div class="in-le">密码</div>
                    <input type="password" class="in-ce js-password" placeholder="6-16位字母或者数字">
                </li>          
            </ul> 
            <div class="sjrz-button-yi"><div class="sjrz-button js-register">立即注册</div></div>       
        </div>
        <div class="sjrz-bottom">
            <div class="sjrz-bot-di">
                <div class="di-h2">规则：</div>
                <div class="di-h2">1.规规则规则规则规则规则规则则</div>
                <div class="di-h2">2.规规则规则规则规则规则规则则</div>
                <div class="di-h2">3.规规则规则规则规则规则规则则</div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="menu"}
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('.js-register').on('click', function () {
            var phone = $('.js-phone').val();
            var password = $('.js-password').val();
            var code = $('.js-code').val();
            if (!is_mobile(phone)) {
                mui.alert('请填写正确格式手机号');
                return false;
            }
            if (!code) {
                mui.alert('请填写验证码');
                return false;
            }
            if (!password) {
                mui.alert('请填写密码');
                return false;
            }
            
            $.post("{:url('business/pub/register')}", {phone: phone, password: password, code: code}, function (res) {
                if (res.code == '1') {
                    setTimeout(function () {
                        location.href = res.url;
                    }, 2000);
                }
                mui.toast(res.msg);
            }, 'json');

        });

        //发送验证码
        $('.js-yzm').click(function () {
            var phone = $('.js-phone').val();
            if (!is_mobile(phone)) {
                mui.toast('请填写正确格式手机号');
                return false;
            }
            var obj = $(this);
            if (obj.attr('is_allow_click') == 1) {
                settime($(this));
                $.post("{:url('business/pub/sendcode')}", {phone: phone}, function (res) {
                    mui.toast(res.msg);
                }, 'json');
            }
        });
    });

    //验证码发送
    var countdown = 60;
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('is_allow_click', 1);
//            obj.attr('disabled', false);
            //obj.removeattr("disabled"); 
            obj.text("获取验证码");
            countdown = 60;
            return;
        } else {
            obj.attr('is_allow_click', 0);
//            obj.attr('disabled', true);
            obj.text("重发(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
            settime(obj)
        }, 1000);
    }
</script>
{/block}